/*
*	(*^。^*) TFrameWork License (*^。^*)
*/

/*
 *  Title :  
 *          
 *  Description :  
 *          
 *          
 *  Date : 
 *
 *  Author : DengPing
 *
 *  Modify : 
 */

using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Playables;

namespace TFrameWork.Module.ActionEditor
{
    public class AnimUnit : AnimBehaviour
    {
        private AnimationClipPlayable _animation;
        
        public AnimUnit(PlayableGraph graph, AnimationClip clip) : base(graph)
        {
            _animation = AnimationClipPlayable.Create(graph, clip);
            _adapterPlayable.AddInput(_animation, 0, 1f);
            
            Disable();
        }

        public override void Enable()
        {
            base.Enable();
            _adapterPlayable.SetTime(0f);
            _animation.SetTime(0f);
            
            _adapterPlayable.Play();
            _animation.Play();
        }

        public override void Disable()
        {
            base.Disable();
            _adapterPlayable.Pause();
            _animation.Pause();
        }
    }
}
